package com.example.kafka.consumer;

import java.util.Properties;

/**
 * @application:
 * @author: LiYuhang
 * @Date: 2021/6/26 14:35
 * @version: 0.1
 * @Description :
 * @Modified By:
 */
public interface Consumer {
    public static final String DESERIALIZER = "org.apache.kafka.common.serialization.StringDeserializer";

    /**
     * CONSUMER接口
     * @param servers
     * @param groupID
     * @param autoCommit
     * @return
     */
    static Properties creatConfig(String servers,String groupID,boolean autoCommit) {
        Properties config = new Properties();
        config.put("bootstrap.servers",servers);
        config.put("group.id",groupID);
        config.put("enable.auto.commit",autoCommit);
        config.put("auto.commit.interval.ms","1000");
        config.put("auto.offset.reset","earliest");
        config.put("session.timeout.ms",30000);
        config.put("key.deserializer",DESERIALIZER);
        config.put("value.deserializer",DESERIALIZER);
        return config;
    }

    /**
     * 默认kafka地址
     * @param groupID
     * @return
     */
    static Properties getDefaultConfig(String groupID) {
        return creatConfig("47.100.82.240:9092",groupID,true);
    }

    /**
     * 默认配置
     * @param groupID
     * @param autoCommit
     * @return
     */
    static Properties getDefaultConfig(String groupID,boolean autoCommit) {
        return creatConfig("47.100.82.240:9092",groupID,autoCommit);
    }

}
